document.getElementById('loginForm').addEventListener('submit', function(e) {
    e.preventDefault();

    const username = document.getElementById('username').value;
    const password = document.getElementById('password').value;
    const role = document.getElementById('role').value;
    const form = document.getElementById('loginForm');

    // 根据选择的角色设置不同的action
    form.action = 'login.' + role;

    if (username && password) {
        form.submit();
    } else {
        alert('请输入用户名和密码！');
    }
});

window.onload = function() {
    var urlParams = new URLSearchParams(window.location.search);
    var isLogin = urlParams.get("isLogin");
    if(isLogin === "0") {
        alert("用户名或密码错误！");
    }

    // 页面加载时设置初始action
    const role = document.getElementById('role').value;
    document.getElementById('loginForm').action = 'login.' + role;

    // 监听角色选择变化
    document.getElementById('role').addEventListener('change', function() {
        document.getElementById('loginForm').action = 'login.' + this.value;
    });
}